use std::collections::HashMap;

use crate::router::api::i_router::IRouter;
use axum::routing::get;
use axum::{Router, extract, http};
use serde::Deserialize;

pub struct QueryParams {}

impl IRouter for QueryParams {
    fn init_router(&self, router: Router) -> Router {
        let gg = Router::new()
            .route("/obj", get(QueryParams::query_obj))
            .route("/map", get(QueryParams::query_hashmap))
            .route("/raw", get(QueryParams::raw_query_hashmap))
            .route("/header", get(QueryParams::header));
        router.nest("/query", gg)
    }
}

#[derive(Deserialize, Debug)]
pub struct Info {
    name: String,
    age: u8,
}

impl QueryParams {
    pub fn new() -> QueryParams {
        QueryParams {}
    }
    pub async fn query_obj(query: extract::Query<Info>) -> String {
        let info: Info = query.0;
        format!("Query<Info>: {info:?}")
    }
    pub async fn query_hashmap(query: extract::Query<HashMap<String, String>>) -> String {
        format!("extract::Query<HashMap<String, String>>): {query:?}")
    }
    pub async fn raw_query_hashmap(extract::RawQuery(query): extract::RawQuery) -> String {
        format!("extract::Query<HashMap<String, String>>): {query:?}")
    }
    // `HeaderMap` gives you all the headers
    pub async fn header(headers: http::header::HeaderMap) -> String {
        format!("header: {headers:?}")
    }
}
